package com.yang.mybatisplus;


import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;


/**
 * @Description: mybatis-plus代码生成器
 * @author: Yang Qiang
 * @create: 2021-04-28 19:28
 */
public class MyAutoGenerator {
    public static void main(String[] args) {

        // 代码生成器
        AutoGenerator mpg = new AutoGenerator();

        /**
         *全局配置
         */
        GlobalConfig gc = new GlobalConfig();
        // 输出位置
        gc.setOutputDir("D:\\mysql_from");
        gc.setAuthor("doyd");
        gc.setOpen(false);
        gc.setSwagger2(true);
        // 去除service前面的字符
        gc.setServiceName("I%sService");
        // 实体类加后缀名
        gc.setEntityName("%sPO");
        mpg.setGlobalConfig(gc);

        /**
         * 数据源配置
         */
        DataSourceConfig dsc = new DataSourceConfig();
        // 指定IP地址+数据库+表
        dsc.setUrl("jdbc:mysql://192.168.4.30:3306/doyd_ai?useUnicode=true&characterEncoding=utf8&useSSL=false");
        dsc.setDriverName("com.mysql.cj.jdbc.Driver");
        // 账号+密码
        dsc.setUsername("doyd");
        dsc.setPassword("doyd1913");
        mpg.setDataSource(dsc);

        /**
         * 包配置
         */
        PackageConfig pc = new PackageConfig();
        // 父包名
        pc.setParent("com.doyd.ai.admin");
        // 各类型包名
        pc.setEntity("entity.po");
        pc.setMapper("mapper");
        pc.setService("service");
        mpg.setPackageInfo(pc);


        /**
         * 策略配置
         */
        StrategyConfig strategy = new StrategyConfig();
        // 驼峰命名转换
        strategy.setNaming(NamingStrategy.underline_to_camel);
        strategy.setColumnNaming(NamingStrategy.underline_to_camel);
        // 生成lombok注解, false就生成get set toString
        strategy.setEntityLombokModel(true);
        strategy.setRestControllerStyle(true);
        // 指定表(多个用逗号隔开)
        //strategy.setInclude(("affiliated_code," +
        //        "label_info," +
        //        "label_category," +
        //        "mall_category," +
        //        "mall_info," +
        //        "mall_category," +
        //        "mall_channel,"
        //).split(","));
        // 单个表
        strategy.setInclude("ai_rule");
        strategy.setControllerMappingHyphenStyle(true);
        mpg.setStrategy(strategy);

        /**
         * 开始输出代码到文件
         */
        mpg.execute();
    }
}
